package com.example.cardgame.model2

import java.io.Serializable

class Card(private var suit: String, private var rank: String, var isChosen: Boolean = false, var isMatched: Boolean = false) : Serializable {
    companion object {
        val rankStrings = arrayOf("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K")
        val validSuits = arrayOf("♥", "♦", "♠", "♣")
    }

    // 返回卡片的字符串表示
    override fun toString(): String {
        return suit + rank
    }

    // 获取卡片的显示值
    fun getDisplayValue(): String {
        return "$suit$rank"
    }

    // 匹配其他卡片，返回匹配得分
    fun match(otherCards: Array<Card>): Int {
        var score = 0
        if (otherCards.size == 2) {
            val firstCard = otherCards[0]
            val secondCard = otherCards[1]
            // 如果两张卡片的等级与当前卡片相同，得分为8
            if (firstCard.rank == rank && secondCard.rank == rank) {
                score = 8
                // 如果两张卡片的花色与当前卡片相同，得分为3
            } else if (firstCard.suit == suit && secondCard.suit == suit) {
                score = 3
            }
        }
        return score
    }
}